package geppetto.cat.programs;


import geppetto.cat.common.Pair;
import geppetto.cat.corpus.BilingualCorpus;
import geppetto.cat.models.SparseTranslationTable;
import geppetto.cat.models.stats.SparseTranslationTableStats;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;



public class PrintNullTranslationProbs {
	
	//TODO go some place
	static class CompareIntegerDoubleList implements Comparator{

		public int compare(Object arg0, Object arg1) {
			Pair<Integer,Double> p1 = (Pair<Integer,Double>)arg0;
			Pair<Integer,Double> p2 = (Pair<Integer,Double>)arg1;
			if(p1.second() < p2.second()){
				return 1;
			}else{
				return -1;
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		String corpusDescription = args[0];
		int size = Integer.parseInt(args[1]);
		int maxSentenceSize = Integer.parseInt(args[2]);
		
		System.out.println("Corpus " + corpusDescription);
		System.out.println("Size " + size);
		System.out.println("Max Sent length " + maxSentenceSize);
		
		BilingualCorpus forwardCorpus = BilingualCorpus.getCorpusFromFileDescription(corpusDescription, size,maxSentenceSize);
		BilingualCorpus backwardCorpus = forwardCorpus.reverse();	
	
		String forwardModelDir = args[3];
		String backwardModelDir = args[4];
		SparseTranslationTable tableF = SparseTranslationTable
		.LoadTranslationTable(forwardCorpus, forwardModelDir);
		SparseTranslationTable tableB = SparseTranslationTable
		.LoadTranslationTable(backwardCorpus, backwardModelDir);
		
		ArrayList<Pair<Integer, Double>> pairs = new ArrayList<Pair<Integer, Double>>();
		
		for(int i = 0; i < tableF.nullProb.length; i++){
			pairs.add(new Pair(i,tableF.nullProb[i]));
		}
		Collections.sort(pairs, new CompareIntegerDoubleList());
		
		for(int i = 0; i < 100; i++){
			Pair<Integer, Double> p = pairs.get(i);
			System.out.println(forwardCorpus.getForeignString(p.first())+"-"+p.second());
		}
		
	}
}
